<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>camera</title>
	<link rel="stylesheet" href="static/index.css" type="text/css">
   
</head>
<body>
<div class="box">
	<div class="header">
		<span class="title">自动采茶机器人系统V1.0</span>
	</div>
	<div class="menu">
		<li class="active"><a href="/">摄像头测试</a></li>
		<li><a href="#topLoc">嫩芽顶面检测</a></li>
		<li><a href="#sideLoc">嫩芽侧面检测</a></li>
		<li><a href="/servo">机械臂测试</a></li>
	</div>
</div>
<div class="main">
    <div class="zone" id="camera">
		<div class="leftbox"> 
			 <div class="mm">		 
				 <li><button onclick="side4()">4号舵机定焦摄像头</button></li>
				 <li><button onclick="side3()">3号舵机下潜摄像头</button></li>	
			</div>		 
			<div style="color:#f30;margin:15px 5px;">测试舵机参数</div>
			<div class="conf">
				<form id="servoActForm">
					<div class="con0">
					 <label>选择舵机的ID</label>
					 <select id="servoID">
						<option value="1">1号</option>
						<option value="2">2号</option>
						<option value="3">3号</option>
						<option value="4">4号</option>
                                                <option value="5">5号</option>
					 </select>
				  </div>
				  <div class="con0">
					 <label>前进的速度</label>
					 <input type="text" id="fvel" name="fvel" placeholder="输入前进速度（59.3步/秒~1mm)">
				  </div>
				   <div class="con0">
					 <label>前进加速度</label>
					 <input type="text" id="facc" name="facc" placeholder="输入前进加速度" value="0">
				  </div>
				  <div class="con0">
					 <label>前进的距离</label>
					 <input type="text" id="fdis" name="fdis" placeholder="输入前进距离(毫米)">
				  </div>
				  <div class="con0">
					 <label>到达目标位置</label>
					 <input type="text" id="floc" name="floc" placeholder="输入目标位置">
				  </div>
				  <div class="con0">
					 <label>控制指令</label>
					 <input type="text" id="flag" value="1" placeholder="1:前进 -1:后退"> 					 
				  </div>
				  <div class="con0">
				       <input type="submit" name="submit" value="开始执行">
					   <input type="button" name="stop" id="stop" value="终止执行">
				  </div>				  
				</form>	
			</div> 
			<div class="res" id="resList">
			      <div id="currLoc"></div>
			</div>
		</div> 
        <div class="rightbox">   	
			<div class="con">
			    <div id="index" style="color:#f30;">4号舵机定焦摄像头</div>				
				<img id="targetC" src="/video_feed?id=1" alt="" width="100%">
			</div>
		</div> 
	 <div class="clear">  </div>
	</div>    	
</div>
</body>
</html>
<script type="text/javascript" src="static/jquery.js"></script>
<script type="text/javascript">
 function side3(){
   $('#index').html("现在查看4号下潜摄像头！");
   $('#targetC').attr("src","/video_feed?id=-1");
   
}
function side4(){
   $('#index').html("现在查看3号定焦摄像头！");
   $('#targetC').attr("src","/video_feed?id=1");
} 

//开始舵机指令
$("#servoActForm").submit(function(e){
	e.preventDefault();
    var params={};
	params.id=$('#servoID').val();
	params.fvel = $('#fvel').val();	
	params.facc = $('#facc').val();
	params.fdis = $('#fdis').val();
	params.flag = $('#flag').val();
    $.post('/api/servoAct',params,function(res){
	console.log(res);
	  if(res.status==666){
		$('#currLoc').html("当前位置:"+res.current_position);
	  }
	})
})

//停止舵机指令
$('#stop').click(function(e){
   e.preventDefault();
    var params={};
	params.id=$('#servoID').val();	
	params.isStop = true;
    $.post('/api/servoStop',params,function(res){
	  console.log(res); 
	})
})
</script>

